package starcoast.bocai.com.starcoast.activitys.user;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import starcoast.bocai.com.starcoast.R;
import starcoast.bocai.com.starcoast.common.BaseActivity;
import starcoast.bocai.com.starcoast.fragments.order.AllOrderFragment;
import starcoast.bocai.com.starcoast.fragments.order.CompleteOrderFragment;
import starcoast.bocai.com.starcoast.fragments.order.ShipedOrderFragment;
import starcoast.bocai.com.starcoast.fragments.order.WaitShipOrderFragment;
import starcoast.bocai.com.starcoast.fragments.usermovable.MyPartTopicFragment;
import starcoast.bocai.com.starcoast.fragments.usermovable.MyPublicTopicFragment;
import starcoast.bocai.com.starcoast.view.MyViewPager;
import starcoast.bocai.com.starcoast.view.ViewFindUtils;

/**
 * Created by admin on 2016/6/15.
 */
public class MyOrderActivity extends BaseActivity {
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {
            "全部", "待发货","待收货","已完成"
    };
    private MyPagerAdapter mAdapter;
    @Bind(R.id.my_order_tab)
    SlidingTabLayout my_order_tab;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_order);
        ButterKnife.bind(this);
        initToolbar("我的话题");
        initToolBack();
        initView();
    }
    private void initView(){
        mFragments.add(new AllOrderFragment());
        mFragments.add(new WaitShipOrderFragment());
        mFragments.add(new ShipedOrderFragment());
        mFragments.add(new CompleteOrderFragment());
        View decorView = getWindow().getDecorView();
        ViewPager vp = ViewFindUtils.find(decorView, R.id.vp);
        mAdapter = new MyPagerAdapter(getSupportFragmentManager());
        vp.setAdapter(mAdapter);
        my_order_tab.setViewPager(vp);
        vp.setCurrentItem(0);
    }
    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }
}
